#ifndef __MEASUREMENT_H__
#define __MEASUREMENT_H__

#include <iostream>
#include <MeasurementFormatter.h>

typedef int Amount;

template<typename Unit>
    struct Measurement
    {
        Measurement(const Amount&, const Unit &);

        bool
        operator==(const Measurement&) const;

        bool
        operator!=(const Measurement&) const;

        Measurement
        operator+(const Measurement&) const;

        void
        output(std::ostream&, const MeasurementFormatter<Unit>&) const;

    private:
        Amount amountInBaseUnit_m;
    };

template<class Unit>
    Measurement<Unit>::Measurement(const Amount& amount, const Unit& unit) :
        amountInBaseUnit_m(unit.convertToBaseUnit(amount))
    {
    }

template<class Unit>
    bool
    Measurement<Unit>::operator==(const Measurement<Unit>& measurement) const
    {
        return amountInBaseUnit_m == measurement.amountInBaseUnit_m;
    }

template<class Unit>
    bool
    Measurement<Unit>::operator!=(const Measurement<Unit>& measurement) const
    {
        return !(*this == measurement);
    }
template<class Unit>
    Measurement<Unit>
    Measurement<Unit>::operator+(const Measurement<Unit>& measurement) const
    {
        Amount amount = amountInBaseUnit_m + measurement.amountInBaseUnit_m;
        return Measurement(amount, Unit::getBaseUnit());
    }

template<class Unit>
    void
    Measurement<Unit>::output(std::ostream& out, const MeasurementFormatter<
            Unit>& outputter) const
    {
        outputter.output(out, amountInBaseUnit_m, Unit::getBaseUnit());
    }

#endif

